package fx.samples.scrollbarsample;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollBar;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class ScrollBarSample extends Application {

	final ScrollBar sc = new ScrollBar();
	final Image[] images = new Image[5];
	final ImageView[] pics = new ImageView[5];
	final VBox vb = new VBox();
	DropShadow shadow = new DropShadow();

	@Override
	public void start(final Stage stage) {
		final Group root = new Group();
		final Scene scene = new Scene(root, 180, 180);
		scene.setFill(Color.BLACK);
		stage.setScene(scene);
		stage.setTitle("Scrollbar");
		root.getChildren().addAll(vb, sc);

		shadow.setColor(Color.GREY);
		shadow.setOffsetX(2);
		shadow.setOffsetY(2);

		vb.setLayoutX(5);
		vb.setSpacing(10);

		sc.setLayoutX(scene.getWidth()-sc.getWidth());
		sc.setMin(0);
		sc.setOrientation(Orientation.VERTICAL);
		sc.setPrefHeight(180);
		sc.setMax(360);

		for (int i = 0; i < 5; i++) {
			images[i] =
					new Image(getClass().getResourceAsStream("fw" +(i+1)+ ".jpg"));
			final ImageView pic = pics[i] =
					new ImageView(images[i]);
			pic.setEffect(shadow);
			vb.getChildren().add(pics[i]);
		}

		sc.valueProperty().addListener((ChangeListener<Number>) (ov, old_val, new_val) -> vb.setLayoutY(-new_val.doubleValue()));

		stage.show();
	}

	public static void main(final String[] args) {
		launch(args);
	}
}